/// CreateTime 2020/4/21 16:28
/// CreateUser chen 
/// ProjectName flutter_elf
import 'package:flutter_elf/config/component_index.dart';
import 'package:sqflite/sqflite.dart';
import 'db_manager.dart';

abstract class BaseDb{
  //数据表是否存在
  bool isExist = false;
  //获取表名字
  String getTableName();
  //获取操作对象
//  @mustCallSuper
  Future<Database> getDB() async {
    globalPrint('创建语句=======>' + createSqlStr());
    await createTable(getTableName(), createSqlStr());
    return await DBManager.getInstance().getDB();
  }

  String createSqlStr();

  //创建数据表
  @mustCallSuper
  Future<void> createTable(String name, String createSql) async {
    isExist = await DBManager.getInstance().isTableExits(name);
    if (!isExist) {
      Database db = await DBManager.getInstance().getDB();
      return await db.execute(createSql);
    }
  }
}